from django.http import JsonResponse
from django.shortcuts import render


# Create your views here.
from appAdminUserManagement.models import User


def user_center(request):
    return render(request, 'user_center/user_center.html')

def pwd_change(request):
    print("ok in")
    if request.method == 'POST':
        now_pwd = request.POST.get('now_pwd')
        print(now_pwd)
        new_pwd = request.POST.get('new_pwd')
        print(new_pwd)
        if request.session.get('pwd') == now_pwd:
            User.objects.filter(sid=request.session.get('sid')).update(password=new_pwd)
            request.session['pwd'] = new_pwd
            print('密码修改成功')
            return JsonResponse({
                "code": 0,
                "flag": 0
            })

        else:
            print("用户名或密码错误")
            return JsonResponse({
                "code": 0,
                "flag": -1
            })
    return JsonResponse({
        "code": 0,
        "flag": -1
    })